<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.io.*"%>
<%@ page import="java.net.URL" %>
<%
	String param = request.getParameter("param")==null?"":request.getParameter("param");
	out.clear();
	response.reset();
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
	String filePath = "";
	String fileName = "";

	filePath = request.getAttribute("wjlj")==null?"":request.getAttribute("wjlj").toString();
	fileName = request.getAttribute("title")==null?"":request.getAttribute("title").toString();

	try {
		if (!filePath.equals("")) {
			String mimetype = "application/octet-stream;";
			response.setContentType(mimetype);

			String downFileName = new String(fileName.getBytes("GBK"),"ISO-8859-1");

			String inlineType = "attachment";
			response.setHeader("Content-Disposition", inlineType+ ";filename=\"" + downFileName + "\"");

			//response.setContentLength((int) f.length());// 设置下载内容大小
			byte[] buffer = new byte[1024];// 缓冲区
			BufferedOutputStream output = null;
			BufferedInputStream input = null;
			try {
				URL url = new URL(filePath);
				input   =   new   BufferedInputStream(url.openStream());
				output   =   new BufferedOutputStream(response.getOutputStream());
				int n = (-1);
				while ((n = input.read(buffer, 0, 1024)) > -1) {
					output.write(buffer, 0, n);
				}

				response.flushBuffer();
			} catch (Exception e) {
				// 用户可能取消了下载
			}
			finally {
				if (input != null)
					input.close();
				if (output != null)
					output.close();
			}
		} else {
			//response.sendRedirect(request.getContextPath()+ "/monitoring/errorservlet.jsp");
			response.getWriter().write("<script language='javascript'>alert('文件未找到');window.history.go(-1);</script>");
		}
		return;
	} catch (Exception ex) {
		// 如果下载失败了就告诉用户此文件下载失败
		response.getWriter().write("<script language='javascript'>alert('文件下载失败');window.history.go(-1);</script>");
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>